<template>
  <div>
    <footer class="asl-footer">
      <div class="footer-container">
        <div class="logo-container">
          <router-link to="/index">
            <img
              :src="logoUrl"
              alt="ASL Logo"
              class="footer-logo"
              loading="lazy"
              @load="handleLogoLoad"
            />
          </router-link>
        </div>
        <!-- 关于我们部分 -->
        <div class="footer-section">
          <h3 class="footer-title">{{$t('navDetails.Transport')}}</h3>
          <ul class="footer-links">
            <li><span @click.prevent="navigateTo('/transport/air')">{{$t('contactInfo.air_freight')}}</span></li>
            <li><span @click.prevent="navigateTo('/transport/sea')">{{$t('contactInfo.sea_freight')}}</span></li>
            <li><span @click.prevent="navigateTo('/transport/rail')">{{$t('contactInfo.rail_transport')}}</span></li>
            <li><span @click.prevent="navigateTo('/transport/road')">{{$t('navDetails.TIRTransport')}}</span></li>
          </ul>
        </div>

        <!-- 网站导航部分 -->
        <div class="footer-section">
          <h3 class="footer-title">{{$t('contactInfo.site_navigation')}}</h3>
          <ul class="footer-links">
            <li><span @click.prevent="navigateTo('/services/warehousing')">{{$t('contactInfo.warehouse_distribution')}}</span></li>
            <li><span @click.prevent="navigateTo('/services/customs')">{{$t('contactInfo.customs_services')}}</span></li>
            <li><span @click.prevent="navigateTo('/services/ecommerce')">{{$t('contactInfo.ecommerce_logistics')}}</span></li>
            <li><span @click.prevent="navigateTo('/services/oversize')">{{$t('contactInfo.insurance_services')}}</span></li>
            <li><span @click.prevent="navigateTo('/services/project-cargo')">{{$t('navDetails.OverweightOversizeCargo')}}</span></li>
          </ul>
        </div>

        <!-- 联系信息部分 -->
        <div class="footer-section contact-info">
          <h3 class="footer-title">{{$t('contactInfo.contact_info')}}</h3>
          <ul class="footer-links">
            <li>{{contactInfoDetails.companyName}}</li>
            <li>{{contactInfoDetails.logisticsPhone}}</li>
            <li>{{$t('contactInfo.phone')}}: {{contactInfoDetails.officePhone}}</li>
            <li>{{$t('contactInfo.email')}}: {{contactInfoDetails.email}}</li>
            <li v-if="contactInfoDetails.address">{{$t('contactInfo.address')}}: {{contactInfoDetails.address}}</li>
          </ul>
        </div>
      </div>

      <!-- 版权信息 -->
      <div class="footer-bottom">
        <p>{{currentYear}} © ASL Logistik GmbH</p>
        <router-link
          v-for="item in legalDocumentsList"
          :key="item.id"
          :to="{ name: 'legalDocuments', params: { id: item.id } }"
          class="legal-link"
        >
          {{item.title}}
        </router-link>
      </div>
    </footer>
  </div>
</template>

<script>
import { getContactInfoContent } from "@/api/contactInfo/contactInfo";
import { debounce } from 'lodash-es';
import {getAllLegalTitles} from "../../../api/legalDocuments/legalDocuments";

export default {
  data() {
    return {
      logoUrl: require("@/assets/asl_images/bottom_logo.png"),
      contactInfoDetails: {},
      currentYear: new Date().getFullYear(),
      legalDocumentsList:[],
    };
  },
  created() {
    this.fetchContactInfo();
    this.getListAllLegalTitles();
  },
  methods: {
    // 获取所有法律文档的标题列表
    getListAllLegalTitles() {
      this.loading = true
      getAllLegalTitles().then(response => {
        this.legalDocumentsList = response.data;
        this.loading = false
      })
    },
    /** 查询底部联系信息 - 添加防抖 */
    fetchContactInfo: debounce(function() {
      getContactInfoContent()
        .then(response => {
          this.contactInfoDetails = response.data;
        })
        .catch(error => {
          console.error("获取联系信息失败:", error);
        });
    }, 300),

    /** 统一路由跳转方法 */
    navigateTo(path) {
      if (this.$route.path !== path) {
        this.$router.push(path);
      }
    },

    /** logo加载处理 */
    handleLogoLoad(event) {
      event.target.classList.add('loaded');
    },

    /** 预加载重要资源 */
    preloadResources() {
      // 预加载logo图片
      const img = new Image();
      img.src = this.logoUrl;
    }
  },

  mounted() {
    this.preloadResources();
  }
};
</script>

<style scoped lang="scss">
.asl-footer {
  background-color: #10162e;
  color: #ecf0f1;
  padding: 40px 0 20px;
  font-family: 'Arial', sans-serif;
  user-select: none;
  cursor: pointer;
}

.footer-container {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  padding: 0 60px;
}

.logo-container {
  flex: 0 0 auto;
  padding: 20px;
  display: flex;
  align-items: center;
  height: 100%;
  min-width: 280px;
}

.footer-logo {
  max-height: 60px;
  width: auto;
  opacity: 0;
  transition: opacity 0.3s ease;

  &.loaded {
    opacity: 1;
  }
}

.footer-section {
  flex: 1;
  min-width: 200px;
  margin-bottom: 30px;
  padding: 0 15px;
}

.footer-title {
  font-size: 18px;
  margin-bottom: 20px;
  padding-bottom: 5px;
  display: inline-block;
}

.footer-links {
  list-style: none;
  padding: 0;
  color: #74767f;
}

.footer-links li {
  margin-bottom: 10px;
  line-height: 1.6;
}

.footer-links span {
  color: #74767f;
  text-decoration: none;
  transition: color 0.3s;
}

.footer-links span:hover {
  color: #fe3231;
}

.contact-info li {
  display: flex;
  align-items: center;
}

.footer-bottom {
  text-align: center;
  padding-top: 20px;
  border-top: 1px solid #34495e;
  margin-top: 20px;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.legal-link {
  padding: 0 20px;
  color: inherit;
  text-decoration: none;
  transition: color 0.3s;

  &:hover {
    color: #fe3231;
  }
}

/* 媒体查询：为小屏幕设备添加移动端样式 */
@media (max-width: 768px) {
  .footer-container {
    flex-direction: column;
    align-items: center;
    padding: 0 20px;
  }

  .logo-container {
    margin-bottom: 30px;
    width: 100%;
    justify-content: center;
    min-width: auto;
  }

  .footer-section {
    flex: 100%;
    margin-bottom: 20px;
    width: 100%;
    text-align: center;
  }
  .contact-info li{
    justify-content: center;
  }
  .footer-links li {
    margin-bottom: 8px;
  }
}

@media (max-width: 480px) {
  .footer-bottom{
    display: flex;
    flex-direction: column;
    a{
      padding: 10px 0;
    }
  }
  .footer-container {
    padding: 0 10px;
  }

  .footer-logo {
    max-height: 40px;
  }

  .footer-title {
    font-size: 16px;
  }

  .footer-links li {
    font-size: 12px;
    line-height: 1.4;
  }
}
</style>
